package com.duobao.game;

import com.duobao.server.Hero;
import com.duobao.server.Map;
import com.duobao.server.Maps;
import com.duobao.server.NPCS;
import com.duobao.view.MainPanel;

import javax.swing.*;
import java.awt.*;
import java.util.Enumeration;

public class DuobaoSwingLaunch extends JFrame {
    public JPanel mainPanel;
    public Hero hero;

    public DuobaoSwingLaunch() {
        hero = new Hero();
        Map map2 = Maps.getMap(hero.getLocation());
        map2.getNpcs().add(hero);

        Thread th = new Thread(hero);
        th.start();

        mainPanel = new MainPanel(this, 1);
        this.add(mainPanel);

        Font font = new Font("宋体", Font.PLAIN, 14);
        Enumeration keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof javax.swing.plaf.FontUIResource) {
                UIManager.put(key, font);
            }
        }
        this.setTitle("夺宝中华4.0");
        this.setIconImage(new ImageIcon("duobaoswing/src/main/resources/image/logo.gif").getImage());
        this.setSize(700, 500);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Maps.JCRW();
        Maps.Thread();
        NPCS.Thread2();


        new DuobaoSwingLaunch();
    }

    public void setPanel(JPanel jpl) {
        this.remove(this.mainPanel);
        this.mainPanel = jpl;
        this.add(jpl);
        this.setVisible(true);
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public void setMainPanel(JPanel mainPanel) {
        this.mainPanel = mainPanel;
    }

    public Hero getHero() {
        return hero;
    }

    public void setHero(Hero hero) {
        this.hero = hero;
    }

}
